package cn.yu.od;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

/**
 * 最小调整顺序次数 / 特异性双端队列
 *
 * @Author : Ning Yu
 * @create 2023/4/26 10:21
 *
 * test case 1
 * 5
 * head add 1
 * tail add 2
 * remove
 * head add 3
 * tail add 4
 * head add 5
 * remove
 * remove
 * remove
 * remove
 * 1
 *
 */
public class TiaoZhengShuXu {

    public static void main(String[] args) {

        ArrayList<Integer> dqueue = new ArrayList<>();

        Scanner scanner = new Scanner(System.in);
        int except = 1;
        int sortTime = 0;
        int count = Integer.parseInt(scanner.nextLine());
        for (int i = 0; i < count * 2; i++) {
            String com = scanner.nextLine();
            if(com.startsWith("head add ")){
                dqueue.add(0, Integer.parseInt(com.substring(com.indexOf("head add ") + "head add ".length())));
            } else if (com.startsWith("tail add ")) {
                dqueue.add(Integer.parseInt(com.substring(com.indexOf("tail add ") + "tail add ".length())));
            } else if (com.equals("remove")) {
                Integer head = dqueue.get(0);
                if (!head.equals(except)){
                    Collections.sort(dqueue);
                    sortTime ++;
                }
                dqueue.remove(dqueue.get(0));
                except ++;
            }
        }
        System.out.println(sortTime);
    }

}
